<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Models\Partner;
use Illuminate\Http\Request;

class PartnerController extends Controller {


    //列表
    public function index(Request $request){
        $params = [
            'status' => (int)$request->get('status',0),
        ];
        $lists = Partner::getList($params);
        return $this->writeJson(0,$lists);
    }


    //更新
    public function update(Request $request)
    {
        $data = $request->all();
        if($data['id']){
            $info = Partner::findOrFail($data['id']);
            $info->update($data);
            return $this->writeJson(0,null,'修改合作伙伴信息成功');
        }else{
            unset($data['id']);
            Partner::create($data);
            return $this->writeJson(0,null,'新增合作伙伴信息成功');
        }
    }


    //删除
    public function destroy(Request $request){
        $id = (int)$request->get('id',0);
        if(empty($id)){
            return $this->writeJson(1,null,'参数错误');
        }
        Partner::destroy($id);
        return $this->writeJson(0);
    }

}
